﻿#pragma once

#include "Save/Persistence.h"
#include "World/World.h"
#include "World/Player.h"
#include "World/BlockRegistry.h"
#include "Scene/BlockOutline.h"
#include "Scene/Skybox.h"
#include "Scene/Effect/PostProcessEffect.h"

class Level
{
public:
  Level(const std::string &saveName);
  ~Level();

  void Update(float deltaTime);
  void Render();
  void RenderGui();

  Ref<Player> GetPlayer() const { return m_player; }
  Ref<World> GetWorld() const { return m_world; }
  Ref<Persistence> GetPersistence() const { return m_persistence; }
  Ref<BlockRegistry> GetBlockRegistry() const { return m_blockRegistry; }

  Skybox &GetSkybox() { return m_skybox; }
  

  void AddPostProcessEffects();

  void EnableGui(bool enable) { m_isOpenGui = enable; }
  void ToggleGui() { m_isOpenGui = !m_isOpenGui; }
  
private:
  float m_deltaTime = 0.0f;
  bool m_isOpenGui = false;

  Ref<Persistence> m_persistence{nullptr};
  Ref<World> m_world{nullptr};
  Ref<Player> m_player{nullptr};
  Skybox m_skybox;
  

  Ref<BlockRegistry> m_blockRegistry{nullptr}; 
  Ref<FrameBuffer> m_fbOpaque{nullptr};
  Ref<FrameBuffer> m_fbLightedOpaque{nullptr};
  Ref<FrameBuffer> m_fbTransparent{nullptr};
  Ref<FrameBuffer> m_fbLightedTransparent{nullptr};
  Ref<FrameBuffer> m_fbShadow{nullptr};

  BlockOutline m_blockOutline{CreateRef<CubeMesh>()};
  std::vector<Ref<PostProcessEffect>> m_postProcessEffects;
};